<?php
/**
 * Reverse bidding system User_model Class
 *
 * helps to achieve common tasks related to the site like flash message formats,pagination variables.
 *
 * @package		Reverse bidding system
 * @subpackage	Models
 * @category	Common_model 
 * @author		Cogzidel Dev Team
 * @version		Version 1.0
 * @link		http://www.cogzidel.com
 
  <Reverse bidding system> 
    Copyright (C) <2009>  <Cogzidel Technologies>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>
    If you want more information, please email me at bala.k@cogzidel.com or 
    contact us from http://www.cogzidel.com/contact 
 
 
 */
	 class User_model extends Model {
	 
	/**
	 * Constructor 
	 *
	 */
	  function User_model() 
	  {
		parent::Model();
				
      }//Controller End
	  
	// --------------------------------------------------------------------
	
	/**
	 * Set Style for the flash messages
	 *
	 * @access	public
	 * @param	string	the type of the flash message
	 * @param	string  flash message 
	 * @return	string	flash message with proper style
	 */
	 
	 function getRoleId($role_name='')
	 {
	 
	 	$conditions = array('role_name'=> $role_name);
	 	$this->db->where($conditions);
	 	$this->db->select('id');
		$query = $this->db->get('roles');		
		$row   = $query->row();
		return $row->id;
	 }//End of flash_message Function
	 
	// --------------------------------------------------------------------
	
	/**
	 * Set Style for the flash messages
	 *
	 * @access	public
	 * @param	string	the type of the flash message
	 * @param	string  flash message 
	 * @return	string	flash message with proper style
	 */
	 
	 function getRoles()
	 {
	 
	 	$this->db->select('id,role_name');
		$query = $this->db->get('roles');		
		return $query->result();
	 }//End of flash_message Function
	 
	// --------------------------------------------------------------------

	/**
	 * create user
	 *
	 * @access	public
	 * @param	string	the type of the flash message
	 * @param	string  flash message 
	 * @return	string	flash message with proper style
	 */
	 function createUser($insertData=array())
	 {
	 	if($this->db->insert('users', $insertData))
            return TRUE;
         else
             return FALSE;
	 }//End of createUser Function

	 function createUserRandom($insertData=array())
	 {
	 	if($this->db->insert('users', $insertData))
            return $this->db->insert_id();
         else
             return FALSE;
	 }//End of createUser Function

	 function createCategoriesRandom($insertData=array())
	 {
	 	if($this->db->insert('user_categories', $insertData))
            return $this->db->insert_id();
         else
             return FALSE;
	 }//End of createUser Function

	function createProjectRandom($insertData=array()){
	 	if($this->db->insert('projects', $insertData))
            return $this->db->insert_id();
         else
             return FALSE;
	}

	 function getClientId(){
	 	$kq = array();
	 	$this->db->from('users');
	 	$this->db->where(array('users.role_id' => 1));
	 	$this->db->select('users.id');
	 	$result =  $this->db->get()->result();
	 	foreach ($result as $value) {
	 		$kq[] = $value->id;
	 	}
	 	return $kq;
	 }
	function getFreelancerId(){
	 	$kq = array();
	 	$this->db->from('users');
	 	$this->db->where(array('users.role_id' => 2));
	 	$this->db->select('users.id');
	 	$result =  $this->db->get()->result();
	 	foreach ($result as $value) {
	 		$kq[] = $value->id;
	 	}
	 	return $kq;
	}

	function getGroupidInCategory($group_ids = array()){
		$group_ids = explode(',', $group_ids);
		$result = array();
		foreach ($group_ids as $item) {
			$this->db->where(array('categories.group_id' => $item));
			$this->db->from('categories');
			$this->db->select('categories.id');
			$kq = $this->db->get()->result();
			foreach ($kq as $value) {
				$result[] = $value->id;
			}
		}
		return $result;

	}




	 // --------------------------------------------------------------------
	
	/**
	 * insert User Contacts
	 *
	 * @access	public
	 * @param	string	the type of the flash message
	 * @param	string  flash message 
	 * @return	string	flash message with proper style
	 */
	 function insertUserContacts($insertData=array())
	 {
	 	$this->db->insert('user_contacts',$insertData);
	 }//End of insertUserContacts Function
	 
	 // --------------------------------------------------------------------
	
	/**
	 * insert User details for invitation
	 *
	 * @access	public
	 * @param	string	the type of the flash message
	 * @param	string  flash message 
	 * @return	string	flash message with proper style
	 */
	 function insertProgrammerInvitation($insertData=array())
	 {
	 	$this->db->insert('project_invitation',$insertData);
	 }//End of insertUserContacts Function

     function insertMultiProgrammerInvitation($insertData=array())
     {
         //$this->db->insert_batch('project_invitation',$insertData);
         $query = "INSERT INTO `project_invitation` (`project_id`,`sender_id`,`receiver_id`,`invite_date`) VALUES";
         $count = count($insertData);
         $dem = 0;
         foreach($insertData as $item){ $dem++;
             if($dem == $count)
                 $comma = "";
             else
                 $comma = ",";
             $query .= "(".$item[1].",".$item[0].",".$item[2].",".$item[3].")".$comma;
         }
         //print_r($query);exit;
         $this->db->query($query);

     }//End of insertUserContacts Function
	 
	 // --------------------------------------------------------------------
	 
	 /**
	 * Update ProgrammerInvitation
	 *
	 * @access	private
	 * @param	array	an associative array of insert values
	 * @return	void
	 */
	 function updateProgrammerInvitation($updateKey=array(),$updateData=array())
	 {
	    $this->db->update('project_invitation',$updateData,$updateKey);
		 
	 }//End of updateProgrammerInvitation Function 
	 
	 // --------------------------------------------------------------------
	 
	 
	 /**
	 * getProgrammerInvitation
	 *
	 * @access	private
	 * @param	nil
	 * @return	object	object with result set
	 */
	 function getProgrammerInvitation($conditions=array(),$fields = array())
	 {
	 	if(count($conditions)>0)		
	 		$this->db->where($conditions);
			
		$this->db->from('project_invitation');

         if($fields!='')
             $this->db->select($fields);
         else
            $this->db->select('project_invitation.id,project_invitation.project_id,project_invitation.sender_id,project_invitation.receiver_id,project_invitation.invite_date');
		 
		$result = $this->db->get();
		return $result;
		
	 }//End of getProgrammerInvitation Function
	 
	 // --------------------------------------------------------------------
	 
	 
	 
	/**
	 * insert Portfolios
	 *
	 * @access	public
	 * @param	string	the type of the flash message
	 * @param	string  flash message 
	 * @return	string	flash message with proper style
	 */
	 function insertPortfolio($insertData=array())
	 {
	 	$this->db->insert('portfolio',$insertData);
	 }//End of insertUserContacts Function
	 
	 // --------------------------------------------------------------------
		
	/**
	 * Update Portfolio
	 *
	 * @access	private
	 * @param	array	an associative array of insert values
	 * @return	void
	 */
	 function updatePortfolio($updateKey=array(),$updateData=array())
	 {
	    $this->db->update('portfolio',$updateData,$updateKey);
		 
	 }//End of updatePortfolio Function 
	 	
	// --------------------------------------------------------------------
	
	/**
	 * insert User Categorys
	 *
	 * @access	public
	 * @param	string	the type of the flash message
	 * @param	string  flash message 
	 * @return	string	flash message with proper style
	 */
	 function insertUserCategories($insertData=array())
	 {
	 	$this->db->insert('user_categories',$insertData);
	 }//End of insertUserContacts Function
	 
	 
 	// --------------------------------------------------------------------
		
	/**
	 * create userBalanceAccount 
	 *
	 * @access	public
	 * @param	string	the type of the flash message
	 * @param	string  flash message 
	 * @return	string	flash message with proper style
	 */
	 function createUserBalance($insertBalance=array())
	 {
	 	$this->db->insert('user_balance', $insertBalance);
	 }//End of createUser Function
	 
 	// --------------------------------------------------------------------
		
	/**
	 * Update users
	 *
	 * @access	private
	 * @param	array	an associative array of insert values
	 * @return	void
	 */
	 function updateUser($updateKey=array(),$updateData=array())
	 {
	    $this->db->update('users',$updateData,$updateKey);
		 
	 }//End of editGroup Function 
	 
	 // --------------------------------------------------------------------
		
	/**
	 * Update bans
	 *
	 * @access	private
	 * @param	array	an associative array of insert values
	 * @return	void
	 */
	 function updateBan($updateKey=array(),$updateData=array())
	 {
	    $this->db->update('bans',$updateData,$updateKey);
		 
	 }//End of editGroup Function
	 
	 // --------------------------------------------------------------------
	 	
	/**
	 * Update usersCategories
	 *
	 * @access	private
	 * @param	array	an associative array of insert values
	 * @return	void
	 */
	 function updateCategories($updateKey=array(),$updateData1=array())
	 {
	    $this->db->update('user_categories',$updateData1,$updateKey);
		 
	 }//End of editGroup Function 
	 
	 
	 
	 		
	/**
	 * Update usersContent
	 *
	 * @access	private
	 * @param	array	an associative array of insert values
	 * @return	void
	 */
	 function updateUserContacts($userContacts=array(),$updateKey2)
	 {
	 	//pr($userContacts);exit;
	    $this->db->update('user_contacts',$userContacts,$updateKey2);
		 
	 }//End of editGroup Function 
	 
	// --------------------------------------------------------------------
	
	
	/**
	 * Get Userslist
	 *
	 * @access	private
	 * @param	nil
	 * @return	object	object with result set
	 */
	 function getUserslist($conditions=array())
	 {
	 	if(count($conditions)>0)		
	 		$this->db->where($conditions);
			
		$this->db->from('users');
		$this->db->join('roles', 'roles.id = users.role_id','left');	
			
	 	$this->db->select('users.id,roles.role_name,users.user_name,users.name,users.role_id,users.country_symbol,users.message_notify,users.password,users.email,users.city,users.state,users.profile_desc,users.rate,users.logo,users.num_reviews,users.user_rating,users.project_notify,users.user_status,users.activation_key,users.created,users.country_id');
		$result = $this->db->get();
		return $result;
		
	 }//End of getUsers Function

	 function getUsersRecommend($conditions = array()){
	 	if(count($conditions)>0)		
	 		$this->db->where($conditions);
			
		$this->db->from('users');
		$this->db->join('roles', 'roles.id = users.role_id','left');	
			
	 	$this->db->select('users.id,roles.role_name,users.user_name,users.name,users.role_id,users.country_symbol,users.message_notify,users.password,users.email,users.city,users.state,users.profile_desc,users.rate,users.logo,users.project_notify,users.user_status,users.activation_key,users.created');
		$result = $this->db->get();
		return $result;
	 }

	// --------------------------------------------------------------------
	
	
	/**
	 * Get Freelancer
	 *
	 * @access	private
	 * @param	nil
	 * @return	object	object with result set
	 */
	 function getFreelancer($conditions=array(),$userId,$limit=array(), $conditionOr = '',$fields = array(),$orderby = array())
	 {

	 	if(count($conditions)>0){
	 		$this->db->where($conditions);
	 		$this->db->where("users.id !=",$userId);
	 		//Check For Limit	
			if(is_array($limit))		
			{
				if(count($limit)==1)
		 			$this->db->limit($limit[0]);
				else if(count($limit)==2)
					$this->db->limit($limit[0],$limit[1]);
			}	

	 	}
	 		
	 	if($conditionOr != ''){
	 		$category_ids = explode(',',$conditionOr);
	 		foreach($category_ids as $item){
	 			$whereOr[] = 'FIND_IN_SET('.$item.', user_categories.user_categories)';
	 		}
	 		if(isset($whereOr) && count($whereOr) > 0){
				$strWhereOr = implode(' OR ', $whereOr);
			}
			$where[] = '('.$strWhereOr.')'; 
	 	}

         if(count($orderby) > 0)
             $this->db->orderby($orderby);
         else
             $this->db->orderby('users.id','desc');

	 	if(isset($where) && count($where) > 0){
	 		$where = implode(' AND ', $where);
	 		$this->db->where($where);
	 	}



		$this->db->from('roles');
		$this->db->join('users', 'roles.id = users.role_id','left');
		$this->db->join("user_categories","user_categories.user_id = users.id",'left');

         if(count($fields) > 0)
             $this->db->select($fields);
         else
             $this->db->select('users.country_id,users.id as uid,roles.role_name,users.user_name,users.name,users.role_id,users.country_symbol,users.message_notify,users.password,users.email,users.city,users.state,users.profile_desc,users.rate,users.project_notify,users.user_status,users.activation_key,users.created,users.last_activity,users.num_reviews,users.user_rating,users.logo,users.refid,user_categories.user_categories');



		$result = $this->db->get();
        //echo $this->db->last_query();exit;
		return $result;
		
	 }//End of getFreelancer Function
	 
	 function getCountFreelancer($conditions=array(),$userId){
	 		if(count($conditions)>0)		
	 		$this->db->where($conditions);
	 		$this->db->where("users.id !=",$userId);
			
			$this->db->from('roles');
			$this->db->join('users', 'roles.id = users.role_id','left');
			$this->db->join("user_categories","user_categories.user_id = users.id",'left');
				
		 	$this->db->select('roles.role_name,users.user_name');
			$result = $this->db->get();
			return $result;
		
	 }


	 
	 // --------------------------------------------------------------------
		
	/**
	 * Get Users
	 *
	 * @access	private
	 * @param	array	conditions to fetch data
	 * @return	object	object with result set
	 */
	 function getUsers($conditions=array(),$fields='',$limit = array(),$orderby = array(), $where_or = null)
	 {
	 
	 	if(count($conditions)>0)		
	 		$this->db->where($conditions);

         if(count($where_or)>0)
             $this->db->or_where($where_or);


         if(is_array($limit))
         {
             if(count($limit)==1)
                 $this->db->limit($limit[0]);
             else if(count($limit)==2)
                 $this->db->limit($limit[0],$limit[1]);
         }



         if(is_array($orderby) and count($orderby)>0)
             $this->db->order_by($orderby[0], $orderby[1]);

         $this->db->from('users');
		$this->db->join('roles', 'roles.id = users.role_id','left');
		$this->db->join('user_categories','user_categories.user_id = users.id','left');



		if($fields!='')
				$this->db->select($fields);
		else 		
	 		$this->db->select('users.country_id,users.id,roles.role_name,users.user_name,users.name,users.role_id,users.country_symbol,users.message_notify,users.password,users.email,users.city,users.state,users.profile_desc,users.rate,users.project_notify,users.user_status,users.activation_key,users.created,users.last_activity,users.num_reviews,users.user_rating,users.logo,users.refid,user_categories.user_categories');
		 
		$result = $this->db->get();
		return $result;
		
	 }//End of getUsers Function

	 function getUsersInputField($inputfield,$password){
	 // 	$this->db->from('users');
	 // 	$this->db->join('roles', 'roles.id = users.role_id','left');
		// $this->db->join('user_categories','user_categories.user_id = users.id','left');
		// $this->db->where(array("user_name = " =>$inputfield,'password' => $password, 'users.user_status' => '1'));
		// $this->db->or_where(array("email = " =>$inputfield));
		$query = "	SELECT users.id,roles.role_name,users.user_name,users.name,users.role_id,users.country_symbol,users.message_notify,users.password,users.email,users.city,users.state,users.profile_desc,users.rate,users.project_notify,users.user_status,users.activation_key,users.created,users.last_activity,users.num_reviews,users.user_rating,users.logo,users.refid,user_categories.user_categories 
					FROM `users` 
					LEFT JOIN `roles` 
					ON  roles.id = users.role_id 
					LEFT JOIN user_categories 
					ON user_categories.user_id = users.id
					WHERE (users.user_name = '".$inputfield ."' OR users.email = '".$inputfield."') 
					AND users.password = '".$password."'
					AND users.user_status = 1 ";
		$result = $this->db->query($query);
		//print_r($this->db->last_query());exit;
		return $result;

	 }



	 function getUserBalance($condition = array(), $fields = ''){
	 	if(is_array($condition) && count($condition) > 0)
	 		$this->db->where($condition);

	 	$this->db->from("user_balance");
	 	if($fields != '')
	 		$this->db->select($fields);
	 	else
	 		$this->db->select("user_balance.id,user_balance.user_id,user_balance.amount");

	 	$result = $this->db->get();
	 	return $result;
	 }

	 // --------------------------------------------------------------------
	 /**
	 * add skill
	 *
	 * @access	private
	 * @param	array	conditions to fetch data
	 * @return	object	object with result set
	 */
	 function addSkillInDB($conditions = array(),$data=array()){
	 	if(count($conditions) > 0){
	 		$this->db->select("user_id,user_categories");
	 		$this->db->where("user_id",$conditions['user_id']);
	 		$query = $this->db->get("user_categories");
	 		$t1 = $query->row_array();
	 		if(count($t1) > 0 && $t1['user_id'] != NULL){
	 			// update
	 			$query = $query->row_array();
	 			$arr1 = array($query['user_categories']);
	 			$arr2 = array($data['user_categories']);
	 			if($arr1[0] == NULL){
	 				$arr3 = array("user_categories"=>implode(",",$arr2));
	 			}else{
	 				$arr3 = array("user_categories"=>implode(",",array_merge($arr1,$arr2)));
	 			} 			
	 			$this->db->where($conditions);
	 			$this->db->update("user_categories",$arr3);
	 			return true;
	 			
	 		}else{
	 			// insert
	 			$arr = array(
	 				"user_id"=>$conditions['user_id'],
	 				"user_categories"=>$data['user_categories']
	 			);
	 			$this->db->insert("user_categories",$arr);
	 			return true;
	 		}
	 	} 	
	 }


	 function getUserSkill($user_id){
	 	$this->db->from("user_categories");
	 	$this->db->select("user_categories");
	 	$this->db->where("user_id",$user_id);
	 	$query = $this->db->get();
	 	$query = $query->row_array();
	 	return $query;

	 }
	 function getNameSkillByString($string){
	 	$singleSkill = explode(',', $string);
	 	$name = "";
	 	$arr = array();
	 	foreach ($singleSkill as $value) {
	 		$this->db->from('categories');
	 		$this->db->select("categories.category_name");
	 		$this->db->where(array("categories.id"=>$value));
	 		$result = $this->db->get();
	 		$result = $result->row();
	 		$name = $result->category_name;
	 		$arr[] = $name;
	 	}
	 	return implode(",", $arr);
	 
	 }
	 function getSingleUsername($userId){
	 	$this->db->from("users");
	 	$this->db->select("user_name","name");
	 	$this->db->where("id",$userId);
	 	$query = $this->db->get();
	 	$query = $query->row_array();
	 	return $query;

	 }

	 function deleteUserSkill($user_id,$name_skill){
	 	$getSkill = $this->user_model->getUserSkill($user_id);
	 	$getSkill = $getSkill['user_categories'];
	 	$explode = explode(",", $getSkill);
	 	foreach ($explode as $key => $value) {
	 		if($value == trim($name_skill)){
	 			unset($explode[$key]);
	 		}
	 	}	 	
	 	$new_arr = implode(',', array_values($explode));
	 	$content = array("user_categories"=>$new_arr);
	 	$this->db->where("user_id",$user_id);
	 	$this->db->update("user_categories",$content);
	 	// unset($explode[$key]);
	 	// return $explode;
	 	//$temp = array_search($name_skill, $getSkill);
	 	//return $getSkill;
	 	//return $this->user_model->getUserSkill($user_id);
	 }


	 function update_username($condition,$updateData){
	 	if(count($condition) > 0){
	 		$this->db->where($condition);
	 		$this->db->update("users",$updateData);
	 		return true;
	 	}
	}

	function update_location($condition,$updateData){
		if(count($condition) > 0){
			$this->db->where($condition);
			$this->db->update("users",$updateData);
			return true;
		}
	}

	function getSingleLocation($userId){
		$this->db->from("users");
	 	$this->db->select("city");
	 	$this->db->where("id",$userId);
	 	$query = $this->db->get();
	 	$query = $query->row_array();
	 	return $query;
	}

	function update_desciprion($condition,$updateData){
		if(count($condition) > 0){
			$this->db->where($condition);
			$this->db->update("users",$updateData);
			return true;
		}
	}

	function getSingleDescription($userId){
		$this->db->from("users");
	 	$this->db->select("profile_desc");
	 	$this->db->where("id",$userId);
	 	$query = $this->db->get();
	 	$query = $query->row_array();
	 	return $query;
	}


	 
	 
	  function getUsers_bal($conditions=array(),$fields='')
	 {
	 	if(count($conditions)>0)		
	 		$this->db->where($conditions);
			
		
		$this->db->from('users');
		$this->db->join('roles', 'roles.id = users.role_id','left');	
		$this->db->join('user_balance', 'users.id = user_balance.user_id','left');	
		
		if($fields!='')
				$this->db->select($fields);
		else 		
	 		$this->db->select('users.id,roles.role_name,users.user_name,users.name,users.role_id,users.country_symbol,users.message_notify,users.password,users.email,users.city,users.state,users.profile_desc,users.rate,users.project_notify,users.user_status,users.activation_key,users.created,users.last_activity,users.num_reviews,users.user_rating,users.logo,user_balance.amount,users.refid');
		 
		$result = $this->db->get();
		return $result;
		
	 }
	 
	 function getUsers_balance($conditions=array(),$fields='',$like=array(),$limit=array(),$orderby = array())
	 {
	 	if(is_array($conditions) and count($conditions)>0)		
	 		$this->db->where($conditions);
			
		//Check For like statement
	 	if(is_array($like) and count($like)>0)		
	 		$this->db->like($like);	
		
		
		//Check For Limit	
		if(is_array($limit))		
		{
			if(count($limit)==1)
	 			$this->db->limit($limit[0]);
			else if(count($limit)==2)
				$this->db->limit($limit[0],$limit[1]);
		}
		//pr($orderby);
		//Check for Order by
		if(is_array($orderby) and count($orderby)>0)
			$this->db->order_by($orderby[0], $orderby[1]);
			
		
		$this->db->from('users');
		$this->db->join('roles', 'roles.id = users.role_id','left');	
		$this->db->join('user_balance', 'users.id = user_balance.user_id','left');	
		
		if($fields!='')
				$this->db->select($fields);
		else 		
	 		$this->db->select('users.id,roles.role_name,users.user_name,users.name,users.role_id,users.country_symbol,users.message_notify,users.password,users.email,users.city,users.state,users.profile_desc,users.rate,users.project_notify,users.user_status,users.activation_key,users.created,users.last_activity,users.num_reviews,users.user_rating,users.logo,user_balance.amount');
		 
		$result = $this->db->get();
		return $result;
		
	 }
	 
	 // --------------------------------------------------------------------
		
	/**
	 * Get Portfolio
	 *
	 * @access	private
	 * @param	array	conditions to fetch data
	 * @return	object	object with result set
	 */
	 function getPortfolio($conditions=array(),$fields='')
	 {
	 	if(count($conditions)>0)		
	 		$this->db->where($conditions);
			
		
		$this->db->from('portfolio');
		$this->db->join('users', 'users.id = portfolio.user_id','left');	
		
		if($fields!='')
				$this->db->select($fields);
		else 		
	 		$this->db->select('portfolio.users.id as userid,users.user_name,portfolio.title,portfolio.id,portfolio.description,portfolio.main_img,portfolio.attachment1 ,portfolio.categories,portfolio.attachment2');
		 
		$result = $this->db->get();
		return $result;
		
	 }//End of getUsers Function
	 
	  // --------------------------------------------------------------------
		
	/**
	 * Get Bans
	 *
	 * @access	private
	 * @param	array	conditions to fetch data
	 * @return	object	object with result set
	 */
	 function getBans($conditions=array(),$fields='')
	 {
	 	if(count($conditions)>0)		
	 		$this->db->where($conditions);
			
		
		$this->db->from('bans');
		
		if($fields!='')
				$this->db->select($fields);
		else 		
	 		$this->db->select('bans.ban_type,bans.ban_value,bans.id');
		 
		$result = $this->db->get();
		return $result;
		
	 }//End of getBans Function
	 
	 function getBansuser($conditions=array(),$fields='',$like=array(),$limit=array(),$orderby = array())
	 {
	 	//Check For Conditions
	 	if(is_array($conditions) and count($conditions)>0)		
	 		$this->db->where($conditions);
			
		//Check For like statement
	 	if(is_array($like) and count($like)>0)		
	 		$this->db->like($like);	
			
		//Check For Limit	
		if(is_array($limit))		
		{
			if(count($limit)==1)
	 			$this->db->limit($limit[0]);
			else if(count($limit)==2)
				$this->db->limit($limit[0],$limit[1]);
		}	
		//pr($orderby);
		//Check for Order by
		if(is_array($orderby) and count($orderby)>0)
			$this->db->order_by($orderby[0], $orderby[1]);
			
		
		$this->db->from('bans');
		
		if($fields!='')
				$this->db->select($fields);
		else 		
	 		$this->db->select('bans.ban_type,bans.ban_value,bans.id');
		 
		$result = $this->db->get();
		return $result;
		
	 }//End of getBans Function
	 
	 
	  function getSuspenduser($conditions=array(),$fields='',$like=array(),$limit=array(),$orderby = array())
	 {
	 	//Check For Conditions
	 	if(is_array($conditions) and count($conditions)>0)		
	 		$this->db->where($conditions);
			
		//Check For like statement
	 	if(is_array($like) and count($like)>0)		
	 		$this->db->like($like);	
			
		//Check For Limit	
		if(is_array($limit))		
		{
			if(count($limit)==1)
	 			$this->db->limit($limit[0]);
			else if(count($limit)==2)
				$this->db->limit($limit[0],$limit[1]);
		}	
		//pr($orderby);
		//Check for Order by
		if(is_array($orderby) and count($orderby)>0)
			$this->db->order_by($orderby[0], $orderby[1]);
			
		
		$this->db->from('suspend');
		
		if($fields!='')
				$this->db->select($fields);
		else 		
	 		$this->db->select('suspend.suspend_type,suspend.suspend_value,suspend.id');
		 
		$result = $this->db->get();
		return $result;
		
	 }//End of getBans Function
	 



 function getSuspend($conditions=array(),$fields='')
	 {
	 	if(count($conditions)>0)		
	 		$this->db->where($conditions);
			
		
		$this->db->from('suspend');
		
		if($fields!='')
				$this->db->select($fields);
		else 		
	 		$this->db->select('suspend.suspend_type,suspend.suspend_value,suspend.id');
		 
		$result = $this->db->get();
		return $result;
		
	 }//End of getBans Function	 
	 // --------------------------------------------------------------------
		
	/**
	 * Get User Contacts
	 *
	 * @access	private
	 * @param	array	conditions to fetch data
	 * @return	object	object with result set
	 */
	 function getUserContacts($conditions=array(),$fields='')
	 {
	 	if(count($conditions)>0)		
	 		$this->db->where($conditions);
		$this->db->from('user_contacts');
		
		if($fields!='')
				$this->db->select($fields);
		else	
	 	$this->db->select('user_contacts.id,user_contacts.msn,user_contacts.gtalk,user_contacts.yahoo,user_contacts.skype');
		 
		$result = $this->db->get();
		return $result;
		
	 }//End of getUserContacts Function
	 
	 //---------------------------------------------------------------------------------------------------------------//
	 
	 /**
	 * Get User Categories
	 *
	 * @access	private
	 * @param	array	conditions to fetch data
	 * @return	object	object with result set
	 */
	 function getUserCategories($conditions=array(),$fields='')
	 {
	 	if(count($conditions)>0)		
	 		$this->db->where($conditions);
		$this->db->from('user_categories');
		
		if($fields!='')
				$this->db->select($fields);
		else	
	 	$this->db->select('user_categories.user_categories');
		 
		$result = $this->db->get();
		return $result;
		
	 }//End of getUserContacts Function
	 
	 //---------------------------------------------------------------------------------------------------------------//
	 
	 /**
	 * Get User Categories
	 *
	 * @access	private
	 * @param	array	conditions to fetch data
	 * @return	object	object with result set
	 */
	 function getUsersWithCategories($conditions=array(),$fields='')
	 {
	 	if(count($conditions)>0)		
	 		$this->db->where($conditions);
			
		$this->db->from('users');
		$this->db->join('user_categories', 'user_categories.user_id = users.id','left');
		
		if($fields!='')
				$this->db->select($fields);
		else	
	 	$this->db->select('users.id,users.email,user_categories.user_categories,users.user_name');
		 
		$result = $this->db->get();
		return $result;
		
	 }//End of getUserContacts Function
	 
	// --------------------------------------------------------------------
	
		
		
	/**
	 * Get Users
	 *
	 * @access	private
	 * @param	array	conditions to fetch data
	 * @return	object	object with result set
	 */
	 function allowToPostProject($creator_id = false)
	 {

		
	 }//End of getCategories Function	 
	 
	 
	 /**
	 * Loads userslist for transfer money
	 *
	 * @access	private
	 * @param	nil
	 * @return	void
	 */	
	function userProjectdata($conditions=array())
	{	
		if(count($conditions)>0)		
	 		$this->db->where($conditions);
			 
	 	$this->db->select('users.id,users.user_name,users.role_id');
		$result = $this->db->get('users');
		return $result;
				
	} //Function logout End
	/**
	 * 
	 * Get the favourite and blocked users list from user_list atable
	 * @access	private
	 * @return	favourite and blocked users list
	 */
	 
	 function getFavourite($conditions=array())
	 {
	  	if(count($conditions)>0)		
	 		$this->db->where($conditions);
		$this->db->from('user_list');
	 	$this->db->select('user_list.id,user_list.creator_id,user_list.user_id,user_list.user_name,user_list.user_role');
		$result = $this->db->get();
		//pr($result);
		
		return $result;
	 }//End of flash_message Function
	 
	// --------------------------------------------------------------------
	
	 
	/**
	 * insert User details for favourite users
	 *
	 * @access	public
	 * @param	string	the type of the flash message
	 * @param	string  flash message 
	 * @return	string	flash message with proper style
	 */
	 function addFavourite($insertData=array())
	 {
	 	$this->db->insert('user_list',$insertData);
	 }//End of insertUserContacts Function 
	 
	 /**
	 * Update user_list for favourite users and blockedusers
	 *
	 * @access	private
	 * @param	array	an associative array of update values
	 * @return	void
	 */
	 function updateFavourite($updateData=array(),$conditions=array())
	 {
	    if(count($conditions)>0)		
	 		$this->db->where($conditions);
		$this->db->update('user_list',$updateData);
		 
	 }//End of editGroup Function 

	function updateKeyRand($condition = array(),$insertData = array()){
	 	if(is_array($condition) && count($condition) > 0)
	 		$this->db->where($condition);
	 	$this->db->update("users",$insertData);
	}
	function checkKeyRand($key){
		$this->db->where(array("users.key_rand" => $key));
		$this->db->from("users");
		$this->db->select("users.email,users.id,users.password");
		$result = $this->db->get();
		return $result;
	}
	function checkActiveEmail($key){
		$this->db->where(array("users.active_email" => $key));
		$this->db->from("users");
		$this->db->select("users.email,users.id,users.password");
		$result = $this->db->get();
		return $result;
	}
	 
	 // --------------------------------------------------------------------
	 
	 /**
	 * delete from user_list for favourite users and blockedusers
	 *
	 * @access	private
	 * @param	array	an associative array of delete values
	 * @return	void
	 */
	 function deleteFavourite($conditions=array())
	 {
	    if(count($conditions)>0)		
	 		$this->db->where($conditions);
		$this->db->delete('user_list');
		 
	 }//End of editGroup Function 
	 
	  // --------------------------------------------------------------------
	 
	 /**
	 * delete portfolios
	 *
	 * @access	private
	 * @param	array	an associative array of delete values
	 * @return	void
	 */
	 function deletePortfolio($conditions=array())
	 {
	    if(count($conditions)>0)		
	 		$this->db->where($conditions);
		$this->db->delete('portfolio');
		 
	 }//End of editGroup Function 
	 
	 // --------------------------------------------------------------------
	 
	 /**
	 * delete ban list
	 *
	 * @access	private
	 * @param	array	an associative array of delete values
	 * @return	void
	 */
	 function deleteBan($id=0,$conditions=array())
	 {
	    if(count($conditions)>0)		
	 		$this->db->where($conditions);
			else	
		    $this->db->where('id', $id);
		$this->db->delete('bans');
		 
	 }//End of deleteBan Function 
	 
	  function deleteSuspend($id=0,$conditions=array())
	 {
	    if(count($conditions)>0)		
	 		$this->db->where($conditions);
			else	
		    $this->db->where('id', $id);
		$this->db->delete('suspend');
		 
	 }//End of deleteBan Function 
	 // --------------------------------------------------------------------
	 
	 /**
	 * delete user
	 *
	 * @access	private
	 * @param	array	an associative array of delete values
	 * @return	void
	 */
	 function deleteUser($id=0,$conditions=array())
	 {
	    if(count($conditions)>0)		
	 		$this->db->where($conditions);
			else	
		    $this->db->where('id', $id);
		$this->db->delete('users');
	 }//End of editGroup Function
	 
	 
	  function deleteBookmark($id=0,$conditions=array())
	 {
	    if(count($conditions)>0)		
	 		$this->db->where($conditions);
			else	
		    $this->db->where('id', $id);
		$this->db->delete('bookmark');
	 }//End of editGroup Function
	 
	  function deleteFile($id=0,$conditions=array())
	 {
	    if(count($conditions)>0)		
	 		$this->db->where($conditions);
			else	
		    $this->db->where('id', $id);
		$this->db->delete('files');
	 }//End of editGroup Function
	  
	  function deleteBalance($id=0,$conditions=array())
	 {
	    if(count($conditions)>0)		
	 		$this->db->where($conditions);
			else	
		    $this->db->where('id', $id);
		$this->db->delete('user_balance');
	 }//End of editGroup Function
	  function deleteCategory($id=0,$conditions=array())
	 {
	    if(count($conditions)>0)		
	 		$this->db->where($conditions);
			else	
		    $this->db->where('id', $id);
		$this->db->delete('user_categories');
	 }//End of editGroup Function
	  function deleteContact($id=0,$conditions=array())
	 {
	    if(count($conditions)>0)		
	 		$this->db->where($conditions);
			else	
		    $this->db->where('id', $id);
		$this->db->delete('user_contacts');
	 }//End of editGroup Function
	  function deleteUserlist($id=0,$conditions=array())
	 {
	    if(count($conditions)>0)		
	 		$this->db->where($conditions);
			else	
		    $this->db->where('id', $id);
		$this->db->delete('user_list');
	 }//End of editGroup Function
	 // --------------------------------------------------------------------

	/**
	 * create ban
	 *
	 * @access	public
	 * @param	string	the type of the flash message
	 * @param	string  flash message 
	 * @return	string	flash message with proper style
	 */
	 function insertBan($insertData=array())
	 {
	 	$this->db->insert('bans', $insertData);
	 }//End of createUser Function
	 
	 // --------------------------------------------------------------------
	
	/**
	 * 
	 * Get the favourite and blocked users list from user_list atable
	 * @access	private
	 * @return	favourite and blocked users list
	 */
	 
	 function getNumUsersByMonth($mon,$year,$rid)
	 {
	 	$query = "SELECT count(*) as cnt FROM users WHERE role_id = $rid AND FROM_UNIXTIME(created, '%c,%Y') = '$mon,$year' ";
	  	$que = $this->db->query($query);
	 	
		$res = $que->row();
		
		return $res->cnt;
	 }//End of flash_message Function
	 
	 // --------------------------------------------------------------------
	 
	 /**
	 * select from user_list from admin
	 *
	 * @access	private
	 * @param	array	an associative array of delete values
	 * @return	void
	 */
	 function viewAdmin($conditions=array())
	 {
		if(count($conditions)>0)		
	 		$this->db->where($conditions);
		$this->db->from('admins');
	 	$this->db->select('admins.id,admins.admin_name,admins.password');
		$result = $this->db->get();
		
		return $result->result();
	 }//End of Function 
	 
	  function viewAdminuser($conditions=array())
	 {
		if(count($conditions)>0)		
	 		$this->db->where($conditions);
		$this->db->from('admins');
	 	$this->db->select('admins.id,admins.admin_name,admins.password');
		$result = $this->db->get();
		
		return $result;
	 }//End of Function 
	 
	 
	 
	 
	 function viewAdmins($conditions=array(),$fields='',$like=array(),$limit=array(),$orderby = array())
	 {
		//Check For Conditions
	 	if(is_array($conditions) and count($conditions)>0)		
	 		$this->db->where($conditions);
			
		//Check For like statement
	 	if(is_array($like) and count($like)>0)		
	 		$this->db->like($like);	
		
		
		//Check For Limit	
		if(is_array($limit))		
		{
			if(count($limit)==1)
	 			$this->db->limit($limit[0]);
			else if(count($limit)==2)
				$this->db->limit($limit[0],$limit[1]);
		}
		//pr($orderby);
		//Check for Order by
		if(is_array($orderby) and count($orderby)>0)
			$this->db->order_by($orderby[0], $orderby[1]);
			 
		$this->db->from('admins');
	 	$this->db->select('admins.id,admins.admin_name,admins.password');
		$result = $this->db->get();
		return $result->result();
	 }//End of Function 
	 // --------------------------------------------------------------------
	 
	 /**
	 * insert User details for admin
	 *
	 * @access	public
	 * @param	string	the type of the flash message
	 * @param	string  flash message 
	 * @return	string	flash message with proper style
	 */
	 function addAdmin($insertData=array())
	 {
	 	$result = $this->db->insert('admins',$insertData);
		return $result;
	 }//End of Function 
	 
	 function getAdmin($conditions=array(),$fields='')
	 {
	 	if(count($conditions)>0)		
	 		$this->db->where($conditions);
			
		
		$this->db->from('admins');
		
		if($fields!='')
				$this->db->select($fields);
		else 		
	 		$this->db->select('admins.id,admins.admin_name,admins.password');
		 
		$result = $this->db->get();
		return $result;
		
	 }//End of getBans Function
	 
	 /**
	 * Update user_list for admin
	 *
	 * @access	private
	 * @param	array	an associative array of update values
	 * @return	void
	 */
	 function updateAdmin($conditions=array(),$updateData=array())
	 {
	    if(count($conditions)>0)		
	 		$this->db->where($conditions);
		$result = $this->db->update('admins',$updateData);
		return $result;
		 
	 }//End of Function 
	 
	 // --------------------------------------------------------------------
	 
	 /**
	 * delete from user_list for admin
	 *
	 * @access	private
	 * @param	array	an associative array of delete values
	 * @return	void
	 */
	 function deleteAdmin($conditions=array())
	 {
	    if(count($conditions)>0)		
	 		$this->db->where($conditions);
		$result = $this->db->delete('admins');
		return $result;
	 }//End of Function 
	 
	 // --------------------------------------------------------------------
	 
	  function getUsersfromusername($condition='')
	{
		
		$query='SELECT * FROM `users` WHERE '.$condition;
		//$this->db->where($condition);
		//$this->db->select('id,email,user_name');
		//$this->db->from('users');
		$result=$this->db->query($query);
		return($result);
	}
	
	
	function addRemerberme($insertData=array(),$expire)
	{
	
		 $this->auth_model->setUserCookie('inputfield',$insertData['inputField'], $expire);
		 $this->auth_model->setUserCookie('pwd',$insertData['password'], $expire);
		 
	}
		
	function removeRemeberme()
	{
	
	  $this->auth_model->clearUserCookie(array('inputfield','pwd'));
	  
	}

	function getUsersMoreInvite($userCate,$not_in,$id_other,$limit = array()){
		$not_in = implode(",", $not_in);
		$uCate = explode(',', $userCate);
		$count = count($uCate);
		$dem = 0;
		$query = 	"SELECT users.id as uid,users.user_name,users.user_rating,users.logo,user_categories.user_categories
					FROM users
					INNER JOIN user_categories ON users.id = user_categories.user_id
					WHERE (";
		foreach ($uCate as $value) {
			$dem++;
			if($dem == $count)
				$or = "";
			else
				$or = "OR";
			$query .= "FIND_IN_SET($value,user_categories.user_categories) ".$or." ";
		}
		$query .= ") AND users.role_id = 2 AND users.is_deleted = 0 AND users.id != ".$id_other;
		$query.= " AND users.id NOT IN ($not_in) ORDER BY users.user_rating desc ";
		if(is_array($limit) && count($limit) > 0){
			if(count($limit)==1)
				$query .= "LIMIT ".$limit[0];
	 			//$this->db->limit($limit[0]);
			else if(count($limit)==2)
				$query .= "LIMIT ".$limit[1].",".$limit[0];
				//$this->db->limit($limit[0],$limit[1]);
		}

		//print_r($query);exit;
		$result = $this->db->query($query);
		return $result;

	}

	function getFreelancerRecommendInvite($userCate,$user_id,$limit=array()){
		$uCate = explode(',', $userCate);
		$count = count($uCate);
		$dem = 0;
		$query = 	"SELECT users.id as uid,users.user_name,users.user_rating,users.logo,user_categories.user_categories
					FROM users
					INNER JOIN user_categories ON users.id = user_categories.user_id
					WHERE (";
		foreach ($uCate as $value) {
			$dem++;
			if($dem == $count)
				$or = "";
			else
				$or = "OR";
			$query .= "FIND_IN_SET($value,user_categories.user_categories) ".$or." ";
		}
		$query .= ") AND users.role_id = 2 AND users.is_deleted = 0 AND users.id != ".$user_id." ORDER BY users.user_rating desc ";
		if(is_array($limit) && count($limit) > 0){
			if(count($limit)==1)
				$query .= "LIMIT ".$limit[0];
	 			//$this->db->limit($limit[0]);
			else if(count($limit)==2)
				$query .= "LIMIT ".$limit[1].",".$limit[0];
				//$this->db->limit($limit[0],$limit[1]);
		}

		//print_r($query);exit;
		$result = $this->db->query($query);
		return $result;
	}

	/**
	 * create user
	 *
	 * @access	public
	 * @param	string	the type of the flash message
	 * @param	string  flash message 
	 * @return	string	flash message with proper style
	 */
	
	function getSameProject($pr_cate,$pid,$limit = array()){
		$pCateId = explode(',', $pr_cate);
		$count = count($pCateId);
		$dem = 0;
		$query = 	"SELECT users.id as uid,users.user_name,projects.id as pid,projects.project_name,projects.project_categories,projects.group_id,projects.budget_max,projects.attachment_avatar as logo
					FROM projects
				 	INNER JOIN users ON users.id = projects.creator_id
					WHERE (";
		foreach ($pCateId as $value) {
			$dem++;
			if($dem == $count)
				$or = "";
			else
				$or = "OR";

		 	$query .= "FIND_IN_SET($value,projects.project_categories) ".$or." ";
		}
		$query .= ") AND projects.is_deleted = 0 AND projects.id != ".$pid." ORDER BY projects.views desc ";
		if(is_array($limit) && count($limit) > 0)
		{
					if(count($limit)==1)
						$query .= "LIMIT ".$limit[0];
			 			//$this->db->limit($limit[0]);
					else if(count($limit)==2)
						$query .= "LIMIT ".$limit[1].",".$limit[0];
						//$this->db->limit($limit[0],$limit[1]);
		}

		//print_r($query);exit;
		$result = $this->db->query($query);
		return $result;
	}

	function getUsersByUserCategory($project_categories,$limit = array()){
		$pCateId = explode(',', $project_categories);
		$count = count($pCateId);
		$dem = 0;
		$query = 	"SELECT users.id,users.user_name,users.name,users.role_id,users.country_symbol,users.message_notify,users.password,users.email,users.city,users.state,users.profile_desc,users.rate,users.project_notify,users.user_status,users.activation_key,users.created,users.last_activity,users.num_reviews,users.user_rating,users.logo,users.refid,user_categories.user_categories,users.country_id
					FROM users
				 	INNER JOIN user_categories ON user_categories.user_id = users.id
					WHERE (";
		foreach ($pCateId as $value) { 
			$dem++;
			if($dem == $count)
				$or = "";
			else
				$or = "OR";

		 	$query .= "FIND_IN_SET($value,user_categories.user_categories) ".$or." ";
		}
		$query .= ") AND users.role_id = 2";

		if(is_array($limit) && count($limit) > 0)
		{
			if(count($limit)==1)
				$query .= "LIMIT ".$limit[0];
	 			//$this->db->limit($limit[0]);
			else if(count($limit)==2)
				$query .= "LIMIT ".$limit[1].",".$limit[0];
		}
		$result = $this->db->query($query);
		return $result->result();
	}// end function

	function getUserScore($userId){
		if (!isset($this->loggedInUser->id)) {
            $this->session->set_flashdata('flash_message', $this->common_model->flash_message('error', $this->lang->line('You must be login access to this page')));
            redirect('info');
        }
        $this->db->from("user_balance");
        $this->db->select("user_balance.amount,user_balance.id");
        $this->db->where(array("user_balance.user_id" => $userId));
        $result = $this->db->get();

        return $result->row();
	}


	function checkEmailExists($email){
		$this->db->from("users");
		$this->db->where(array("email"=>$email));
		$this->db->select("users.id");
		$result = $this->db->get();
		return $result;
	}
	function checkEmailPassIsExists($condition = array()){
		if(is_array($condition) && count($condition) > 0)
			$this->db->where($condition);
		$this->db->from("users");
		$this->db->select("users.id");
		$result = $this->db->get();
		//print_r($this->db->last_query());exit;
		return $result;
	}

	function checkPassExists($condition = array()){
		if(is_array($condition) && count($condition) > 0)
			$this->db->where($condition);
		$this->db->from("users");
		$this->db->select("users.user_name");
		$result = $this->db->get();
		//print_r($this->db->last_query());exit;
		return $result;
	}

	function checkUsernameExists($username){
		$this->db->from("users");
		$this->db->where(array("user_name"=>$username));
		$this->db->select("users.id");
		$result = $this->db->get();
		return $result;
	}

	function checkUserPassword($condition = array()){
		if(is_array($condition) && count($condition) > 0)
			$this->db->where($condition);
		$this->db->select("users.id");
		$result = $this->db->get();
		return $result;
	}

	function updatePassword($condition = array(), $updateData = array())
    {
        if (is_array($condition) && count($condition) > 0)
            $this->db->where($condition);
        $this->db->update('users', $updateData);
    }
    function addUserFacebook($insertData = array()){
        return $this->db->insert('user_facebook', $insertData);
    }
     function getUserFacebook($conditions=array(),$fields='')
     {
         if(count($conditions)>0)
             $this->db->where($conditions);


         $this->db->from('user_facebook');

         if($fields!='')
             $this->db->select($fields);
         else
             $this->db->select('user_facebook.id');

         $result = $this->db->get();
         return $result;

     }//End of getUsers Function
	function getTotalProjectUserDone($condition = array()){
		if(is_array($condition) && count($condition) > 0)
			$this->db->where($condition);
		$this->db->select("projects.id");
		$this->db->from("projects");
		$result = $this->db->get();
		return $result->num_rows();
	}
    function getUsersRandom($conditions=array(),$fields='',$limit = array(),$orderby = array(),$where_not_in = array())
    {

         if(count($conditions)>0)
             $this->db->where($conditions);

         if(is_array($where_not_in)){
             if(count($where_not_in) > 0){
                 $this->db->where_not_in('users.id',$where_not_in);
             }
         }


         if(is_array($limit))
         {
             if(count($limit)==1)
                 $this->db->limit($limit[0]);
             else if(count($limit)==2)
                 $this->db->limit($limit[0],$limit[1]);
         }



         if(is_array($orderby) and count($orderby)>0)
             $this->db->order_by($orderby[0], $orderby[1]);

         $this->db->from('users');
         $this->db->join('roles', 'roles.id = users.role_id','left');
         $this->db->join('user_categories','user_categories.user_id = users.id','left');



         if($fields!='')
             $this->db->select($fields);
         else
             $this->db->select('users.country_id,users.id,roles.role_name,users.user_name,users.name,users.role_id,users.country_symbol,users.message_notify,users.password,users.email,users.city,users.state,users.profile_desc,users.rate,users.project_notify,users.user_status,users.activation_key,users.created,users.last_activity,users.num_reviews,users.user_rating,users.logo,users.refid,user_categories.user_categories');

         $result = $this->db->get();
         return $result;

    }//End of getUsers Function
    function getCountCategorybyUser($cate_id = null){
        if($cate_id != null) {
            $result = $this->db->query("SELECT user_categories.user_categories FROM `user_categories` where FIND_IN_SET({$cate_id},user_categories.user_categories)");
            return $result;
        }else{
            return false;
        }
    }
    function addWatchList($insertData = array()){
        $this->db->insert('user_watchlist',$insertData);
    }
     function removeWatchList($conditions=array())
     {
         if(count($conditions)>0)
             $this->db->where($conditions);

         $this->db->delete('user_watchlist');
     }//End of editGroup Function
    function getWatchList($conditions = array(),$fields = array()){
        if(count($conditions)>0)
            $this->db->where($conditions);

        $this->db->from('user_watchlist');

        if(count($fields) > 0)
            $this->db->select($fields);
        else
            $this->db->select('user_watchlist.user_id,user_watchlist.dev_id');

        $result = $this->db->get();
        return $result;
    }

    //
     function getFreelanceWatchlist($conditions = array(),$fields = array(), $limit = array(), $orderby = array()){
         if(count($conditions)>0)
             $this->db->where($conditions);

         //Check For Limit
         if(is_array($limit))
         {
             if(count($limit)==1)
                 $this->db->limit($limit[0]);
             else if(count($limit)==2)
                 $this->db->limit($limit[0],$limit[1]);
         }
         //pr($orderby);
         //Check for Order by
         if(is_array($orderby) and count($orderby)>0){
             $this->db->order_by($orderby[0], $orderby[1]);
         }else{
             $orderby[] = 'user_watchlist.created';
             $orderby[] = 'asc';
             $this->db->order_by($orderby[0], $orderby[1]);
         }

         $this->db->from('users');
         $this->db->join('user_watchlist', 'user_watchlist.dev_id = users.id','inner');
         $this->db->join('user_categories','user_categories.user_id = users.id','left');
         $this->db->join('projects','projects.programmer_id = user_watchlist.dev_id','left');
         $this->db->join('country','country.id = users.country_id','left');
         $this->db->group_by("users.id");

         if(count($fields) > 0)
             $this->db->select($fields);
         else
             $this->db->select('users.id,users.user_name, users.user_rating, users.num_reviews,users.logo,users.profile_desc,country.country_name,user_categories.user_categories,count(projects.id) AS num_project');

         $result = $this->db->get();
         return $result;
     }

     function getUsersBids($conditions=array(),$fields='',$limit = array(),$orderby = array(), $where_or = null)
     {

         if(count($conditions)>0)
             $this->db->where($conditions);

         if(count($where_or)>0)
             $this->db->or_where($where_or);


         if(is_array($limit))
         {
             if(count($limit)==1)
                 $this->db->limit($limit[0]);
             else if(count($limit)==2)
                 $this->db->limit($limit[0],$limit[1]);
         }



         if(is_array($orderby) and count($orderby)>0)
             $this->db->order_by($orderby[0], $orderby[1]);

         $this->db->from('users');
         $this->db->join('roles', 'roles.id = users.role_id','left');
         $this->db->join('user_categories','user_categories.user_id = users.id','left');
         $this->db->join('bids','bids.user_id = users.id','inner');

         if($fields!='')
             $this->db->select($fields);
         else
             $this->db->select('users.country_id,users.id,roles.role_name,users.user_name,users.name,users.role_id,users.country_symbol,users.message_notify,users.password,users.email,users.city,users.state,users.profile_desc,users.rate,users.project_notify,users.user_status,users.activation_key,users.created,users.last_activity,users.num_reviews,users.user_rating,users.logo,users.refid,user_categories.user_categories, count(bids.id) AS num_bids');

         $result = $this->db->get();
         return $result;

     }
}


// End User_model Class
   
/* End of file User_model.php */ 
/* Location: ./app/models/User_model.php */
?>